Page({
  data: {
    keyword: '',
    goods: [
      { id: 1, img: '/pages/searchResult/1.png', title: '春季外套男士连帽冲锋衣2025新款', price: 99, originPrice: 269, hot: true },
      { id: 2, img: '/pages/searchResult/2.jpg', title: 'HLA海澜之家短袖T恤男2022新款', price: 88, originPrice: 189, new: true },
      { id: 3, img: '/pages/searchResult/3.jpg', title: 'NASA男短袖潮牌名宿夏季', price: 79.9, originPrice: 129, hot: true },
      { id: 4, img: '/pages/searchResult/4.jpg', title: '常规人短袖T恤男夏季韩版', price: 35, originPrice: 99 },
      { id: 5, img: '/pages/searchResult/5.jpg', title: '子丑TEDLON竹纤维短袖', price: 99.9, originPrice: 199 },
      { id: 6, img: '/pages/searchResult/6.jpg', title: 'MLB INGADC官方潮流短袖', price: 99.9, originPrice: 199 }
    ],
    activeTab: 0,
    emptyResult: false,
    guessList: [
      { id: 1, img: '/pages/searchResult/15.jpg', title: '法国兰蔻小黑瓶', price: 399 },
      { id: 2, img: '/pages/searchResult/16.jpg', title: 'HOPE精华水', price: 199 },
      { id: 3, img: '/pages/searchResult/14.jpg', title: 'SK-II神仙水', price: 599 },
      { id: 4, img: '/pages/searchResult/11.jpg', title: '雅诗兰黛小白瓶', price: 499 },
      { id: 5, img: '/pages/searchResult/13.jpg', title: '资生堂红腰子精华', price: 420 },
      { id: 6, img: '/pages/searchResult/12.jpg', title: '欧莱雅复颜抗皱', price: 188 }
    ]
  },
  onLoad(options) {
    let keyword = '';
    if (options.keyword) {
      keyword = decodeURIComponent(options.keyword);
    }
    // 判断是否包含符号类字符
    const symbolReg = /[~!@#$%^&*()_+\-={}\[\]:;"'<>?,./`|\\]/;
    const emptyResult = symbolReg.test(keyword);
    this.setData({ keyword, emptyResult });
  },
  goBack() {
    wx.navigateBack();
  },
  onTabTap(e) {
    const idx = e.currentTarget.dataset.idx;
    let goods = [...this.data.goods];
    if (idx == 2) {
      goods.sort((a, b) => b.price - a.price);
    }
    this.setData({ activeTab: idx, goods });
  }
}); 